package com.liguangting.agentsflex.agent;

import com.agentsflex.core.chain.Chain;
import com.agentsflex.core.chain.ChainEvent;
import com.agentsflex.core.chain.ChainEventListener;
import com.agentsflex.core.chain.event.OnFinishedEvent;
import com.agentsflex.core.chain.event.OnNodeFinishedEvent;
import com.agentsflex.core.chain.event.OnNodeStartEvent;
import com.agentsflex.core.chain.event.OnStartEvent;
import com.agentsflex.core.chain.impl.SequentialChain;

import java.util.HashMap;
import java.util.Map;


/**
 * @author liguangting
 * @date 2024/7/9
 * @description
 */
public class AgentChainTest2 {

    public static void main(String[] args) {
        Chain chain = new SequentialChain();
        chain.addNode(new SimpleAgent1());
        chain.addNode(new SimpleAgent2());

        chain.registerEventListener(OnStartEvent.class, new ChainEventListener() {

            @Override
            public void onEvent(ChainEvent event, Chain chain) {
                System.out.println("OnStartEvent:" + event);
            }
        });

        chain.registerEventListener(OnNodeStartEvent.class, new ChainEventListener() {

            @Override
            public void onEvent(ChainEvent event, Chain chain) {
                System.out.println("OnNodeStartEvent:" + event);
            }
        });

        chain.registerEventListener(OnNodeFinishedEvent.class, new ChainEventListener() {

            @Override
            public void onEvent(ChainEvent event, Chain chain) {
                System.out.println("OnNodeFinishedEvent:" + event);
            }
        });

        chain.registerEventListener(OnFinishedEvent.class, new ChainEventListener() {

            @Override
            public void onEvent(ChainEvent event, Chain chain) {
                System.out.println("OnFinishedEvent:" + event);
            }
        });

        //开始执行
        chain.execute(new HashMap<>());

        //输出结果（多个结果）
        for (Map.Entry<String, Object> entry : chain.getMemory().getAll().entrySet()) {
            System.out.println("执行结果" + entry);
        }
    }
}
